require(['init'], function () {


  function getCourseName(courseTypes) {
    var courseNames = '';
    $.each(courseTypes, function (i, item) {
      if(i != 0) {
        courseNames += ', '
      }
      courseNames += item.coursetypename;
    })
    return courseNames;
  }

  /**
   * 获取教师列表，用于设置教师上课时间
   *
   * @param  {}
   * @return {void}
   */
  function getTeacherList() {
    ajaxMethod({
      url: '/api/teachers',
      success: function (data) {
        var $table = $('<table class="table table-hover"></table>')
        var $thead = $('<thead><tr><th>'+i18next.t('info.teachername')+'</th><th>'+i18next.t('table.course')+'</th></tr></thead>').appendTo($table)
        var $tbody = $('<tbody></tbody>').appendTo($table)
        $.each(data, function (i, item) {
          var $tr = $('<tr></tr>').appendTo($tbody)
          $tr.append('<td>' + item.lastname + '</td>');
          $tr.append('<td>' + getCourseName(item.coursedesc) + '</td>');

          $tr.on('click', function () {
            $(this).addClass('active').siblings().removeClass('active')

            var curIframe = $('iframe')[0]
            curIframe.src = 'teacher_lessontime.html?tuid=' + item.teacheruid;
            curIframe.contentWindow.location.reload()
          })
        })

        $table.appendTo($('#J_teacherlist'))
      }
    })
  }

  getTeacherList()

})
